<!DOCTYPE html>
<html lang="en">
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <!-- Meta, title, CSS, favicons, etc. -->
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">

    <title>自动化运维平台</title>

    <!-- Bootstrap -->
    <link href="{{url_for('static',filename='resource/css/bootstrap.min.css')}}" rel="stylesheet">
    <!-- Font Awesome -->
    <link href="{{url_for('static',filename='resource/css/font-awesome.min.css')}}" rel="stylesheet">
    <!-- NProgress -->
    <link href="{{url_for('static',filename='resource/css/nprogress.css')}}" rel="stylesheet">
    <!-- Animate.css -->
    <link href="{{url_for('static',filename='resource/css/animate.min.css')}}" rel="stylesheet">

    <!-- Custom Theme Style -->
    <link href="{{url_for('static',filename='resource/css/custom.min.css')}}" rel="stylesheet">
      <script type="text/javascript">
          var code; //在全局定义验证码
          //产生验证码
          window.onload = createCode;
          function createCode() {
              code = "";
              var codeLength = 4;//验证码的长度
              var checkCode = document.getElementById("gencode");
              var random = new Array(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R',
                      'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z');//随机数
              for (var i = 0; i < codeLength; i++) {//循环操作
                  var index = Math.floor(Math.random() * 36);//取得随机数的索引（0~35）
                  code += random[index];//根据索引取得随机数加到code上
              }
              checkCode.innerHTML = code;//把code值赋给验证码
          }
          //校验验证码
          function validate() {
              var inputCode = document.getElementById("code").value.toUpperCase();
              if (inputCode == code) {
                  return true;
              }
              else if (inputCode.length <= 0) {
                  alert("请输入验证码！");
                  createCode();
                  return false;
              }
              else {
                  alert("验证码输入错误！");
                  createCode();
                  return false;
              }

          }

      </script>
  </head>

  <body class="login">
    <div>
      <a class="hiddenanchor" id="signup"></a>
      <a class="hiddenanchor" id="signin"></a>

      <div class="login_wrapper">
        <div class="animate form login_form">
          <section class="login_content">
            <form method="POST"  action="/login" >
              {{ form.hidden_tag() }}
              <h1>自动化运维平台</h1>
              <div>
                <input type="name" id="{{ form.name.name }}" name="{{ form.name.name }}"class="form-control" placeholder="用户名" required="" />
                {% for error in form.name.errors %}
                    <span style="color: red;">[{{ error }}]</span>
                {% endfor %}<br>
              </div>
              <div>
                <input type="password" id="{{ form.passwd.name }}" name="{{ form.passwd.name }}" class="form-control" placeholder="密码" required="" />
              </div>
              <div>
                  <label class="control-label left">验证码：<span id="gencode"></span>&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp<small class="right" onclick="javascript:createCode()">看不清点我</small></label>

              </div>
              <div>
                  <input type = "text" id="code" class="form-control" placeholder="验证码" required=""/>
              </div>
              <div align="left">
                  {% with messages = get_flashed_messages() %}
                    {% if messages %}

                        {% for message in messages %}
                            <font color="red">{{ message }}</font><br>
                        {% endfor %}

                    {% endif %}
                  {% endwith %}
              </div>
              <div>
                <input type="submit" class="btn btn-default submit"  onclick="javascript:return validate()" value="登录">
              </div>

              <div class="clearfix"></div>

              <div class="separator">


                <div class="clearfix"></div>
                <br />

                <div>
                  <p>©2016 All Rights Reserved.Privacy and Terms</p>
                </div>
              </div>
            </form>
          </section>
        </div>

      </div>
    </div>
  </body>
</html>
